package cn.itcast.ecshop.act;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import cn.itcast.ecshop.R;
import cn.itcast.ecshop.bean.request.OrderListRequest;
import cn.itcast.ecshop.bean.request.OrderSubmitRequest;
import cn.itcast.ecshop.bean.response.OrderListResponse;
import cn.itcast.ecshop.bean.response.OrderSubmitResponse;
import cn.itcast.ecshop.net.BaseReponse;
import cn.itcast.ecshop.net.BaseRequest;
import cn.itcast.ecshop.net.NetUtil;

public class OrderActivity extends BaseActivity {


    private TextView mTextViewContent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTextViewContent = ((TextView) findViewById(R.id.textview_content));
    }


    public void orderSumbit(View view) {

        NetUtil.sendRequest(new OrderSubmitRequest(), OrderSubmitResponse.class, this);
    }

    public void getOrderList(View view) {

        NetUtil.sendRequest(new OrderListRequest(), OrderListResponse.class, this);
    }

    public void getOrderDetail(View view) {


    }

    @Override
    public void onSuccessResult(BaseRequest request, BaseReponse response) {

        if (request instanceof OrderSubmitRequest) {

            OrderSubmitResponse orderSubmitResponse = (OrderSubmitResponse) response;
            OrderSubmitResponse.OrderInfoBean orderInfo = orderSubmitResponse.getOrderInfo();
            String orderId = orderInfo.getOrderId();
            Toast.makeText(this, "订单信息:" + orderId, Toast.LENGTH_SHORT).show();
        } else if (request instanceof OrderListRequest) {

            OrderListResponse orderListResponse = (OrderListResponse) response;
            orderListResponse.getOrderList();
            String response1 = orderListResponse.getResponse();
            Toast.makeText(this, "订单列表:"+response1, Toast.LENGTH_SHORT).show();

        }
        String string = response.toString();
        mTextViewContent.setText(string);
    }


}
